﻿Public Class FormComprasVencidasListado
    Dim classController As New Class_RC_Controller.rc_Facturas()
    
    Function CargarCompras() As DataTable

        Dim dt As New DataTable
        dt = classController.get_ComprasVencidas_All(oiml.dbConn, txtNombre.Text, txtRuc.Text)
        dgCompras.DataSource = dt

        Return dt

        If Not classController.MessageError Is Nothing Then
            MessageBox.Show("Error: " & classController.MessageError.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Function

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarCompras()
    End Sub

    Private Sub txtNombre_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNombre.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarCompras()

        End If
    End Sub

    Private Sub txtRuc_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRuc.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarCompras()

        End If
    End Sub

    Private m_frmRpts As FormReportes
    Public Property frmRpts() As FormReportes
        Get
            Return m_frmRpts
        End Get
        Set(ByVal value As FormReportes)
            m_frmRpts = value
        End Set
    End Property

    Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click

        If frmRpts Is Nothing Then
            frmRpts = New FormReportes()
            frmRpts.tipo_Reporte = "COMPRASVENCIDAS"
            frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
            frmRpts.ShowDialog()
        Else

            If Not frmRpts.Visible Then
                frmRpts = New FormReportes()
                frmRpts.tipo_Reporte = "COMPRASVENCIDAS"
                frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
                frmRpts.ShowDialog()
            Else
                frmRpts.tipo_Reporte = "COMPRASVENCIDAS"
                frmRpts.datos_Reporte = CType(dgCompras.DataSource, DataTable).Copy
                frmRpts.Select()
                frmRpts.Activate()
            End If

        End If

    End Sub

    Private Sub btnCancelar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    
    
    Private Sub FormComprasVencidasListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgCompras.AutoGenerateColumns = False
        CargarCompras()
    End Sub
End Class